package com.zhongwang.mms.module.half.service;

import com.zhongwang.mms.gen.entity.HOrder;
import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.half.dao.HOrderDao;
import com.zhongwang.mms.module.half.model.HInBillModel;
import com.zhongwang.mms.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @description:主表
 * @author: th
 * @time: 2020/3/23 13:17
 */
@Service
public class HOrderService {

    @Autowired
    private HOrderDao hOrderDao;
    @Autowired
    private CreateOrderCodeService createOrderCodeService;

    /**
     * 入库保存主单
     * @param hInBillModel
     * @return
     */
    public HOrder saveHOrder(HInBillModel hInBillModel){
        // 保存入库单主单信息
        HOrder hOrderForm = new HOrder();
        // 获取登入用户实体
        User user = ShiroUtils.getUser();

        hOrderForm = hInBillModel.getFormData();//总单信息
        hOrderForm.setOdrDate(new Date());//制单时间
        hOrderForm.setOdrCode(createOrderCodeService.getInOrderCode());//单据号
        hOrderForm.setOdrTakePerson(user.getName());//制单人
        hOrderForm.setOdrRedFlag(0); //红冲标识
        hOrderForm.setOdrItyFlag(1); //1蓝单2红单

        //保存主单信息
        hOrderDao.insert(hOrderForm);

        return hOrderForm;
    }

    /**
     * 出库保存主单
     * @param hInBillModel
     * @return
     */
    public HOrder saveOutHOrder(HInBillModel hInBillModel) {
        // 保存入库单主单信息
        HOrder hOrderForm = new HOrder();
        // 获取登入用户实体
        User user = ShiroUtils.getUser();

        hOrderForm = hInBillModel.getFormData();//总单信息
        hOrderForm.setOdrDate(new Date());//制单时间
        hOrderForm.setOdrCode(createOrderCodeService.getOutOrderCode());//单据号
        hOrderForm.setOdrTakePerson(user.getName());//制单人
        hOrderForm.setOdrRedFlag(0); //红冲标识
        hOrderForm.setOdrItyFlag(1); //1蓝单2红单

        //保存主单信息
        hOrderDao.insert(hOrderForm);

        return hOrderForm;
    }

}
